<?php 
defined('_JEXEC') or die;
JLoader::register("PResumesHelper", OC_App::getAppPath('resumes') . "/lib/helper.php");

// disable core styles to avoid bs conflict 
OC_Util::$core_styles = array();

$keyword = JRequest::getString('q', '');
$cur_jobid = empty($_['cur_jobid']) ? 0 : $_['cur_jobid'];
?>

<div class="dialogp_content">
   <div class="searchaction">
      <span class="medium">搜索：</span>
      <div class="dialogsearchbg clearfix">
         <input type="text" value="<?=$keyword?>" class="pull-left search_input"/>
         <?php if ( isset($_['calview']) ) { ?>
            <a href="<?=(OCP\Util::linkToRoute('calendar_joblist', array('cview' => 1)) . '&q=%q')?>" class="itemlist pull-right search_btn"></a>
            <?php
         } else { ?>
            <a href="<?=(OC_Helper::linkToRoute('calendar_joblist') . '?q=%q')?>" class="itemlist pull-right search_btn"></a>
            <?php
         }?>
      </div>
   </div>
   
   <div class="cityselect medium songti">
      <?php 
      list($href, $selected) = PResumesHelper::getSearchItemHref($_['cityPageUrl'], 'jc', 'all');
      ?>
      <a href="<?=($selected ? 'javascript:;' : $href)?>" class="displaylist <?=($selected ? 'cur_a'  : '')?>">全部</a>
      <?php 
      if(isset($_['jobcitylist']) && !empty($_['jobcitylist'])) {
         foreach ($_['jobcitylist'] as $jobcity) {
            list($href, $selected) = PResumesHelper::getSearchItemHref($_['cityPageUrl'], 'jc', $jobcity['cityid']);
      ?>
      <a href="<?=($selected ? 'javascript:;' : $href)?>" class="displaylist <?=($selected ? 'cur_a'  : '')?>"><?php echo ProvinceHelper::getMuniProvinceId($jobcity['cityid']) ? $jobcity['province'] : $jobcity['province'] . $jobcity['city']?></a>
      <?php 
         }
      }
      ?>
   </div>
   
   <div class="selectletter medium">
      <?php 
      list($href, $selected) = PResumesHelper::getSearchItemHref($_['ikeyPageUrl'], 'ik', 'all');
      ?>
      <a href="<?=($selected ? 'javascript:;' : $href)?>" class="displaylist <?=($selected ? 'cur_a'  : '')?>">全部</a>
      <?php 
      if(isset($_['jobikeylist']) && !empty($_['jobikeylist'])) {
         foreach ($_['jobikeylist'] as $jobikey) {
            list($href, $selected) = PResumesHelper::getSearchItemHref($_['ikeyPageUrl'], 'ik', $jobikey);
      ?>
      <a href="<?=($selected ? 'javascript:;' : $href)?>" class="displaylist <?=($selected ? 'cur_a'  : '')?>"><?=strtoupper($jobikey == 'other' ? '其他' : $jobikey)?></a>
      <?php 
         }
      }
      ?>
   </div>
   
   <?php if (empty($_['jobList'])): ?>
   <div class="postionlisttable_nodata large yahei" style="text-align: center;">没有对应的职位</div>
   <?php else: ?>
   <div class="postionlisttable medium" style="max-height:300px;">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
         <tr>
            <?php 
            $n=count($_['jobList']);
            for ($i=0; $i < $n; $i++) {
               $job = $_['jobList'][$i];
               if ($i != 0 && ($i%3) == 0) {
                  echo '</tr><tr>';
               }
               list($href, $selected) = PResumesHelper::getSearchItemHref($_['searchUrl'], 'jobid', $job['id']);
            ?>
               <?php if ( isset($_['calview']) ) { ?>
                  <td width="33%"><a id="<?=$job['id']?>" data-jobid="<?=$job['id']?>" data-jobtitle="<?=$job['job_title']?>" href="javascript:;" class="calendarview <?php echo $cur_jobid == $job['id'] ? 'cur_a'  : '';?>"><?=$job['job_title']?></a></td>
                  <?php
               } else { ?>
                  <td width="33%"><a href="<?=($selected ? 'javascript:;' : $href)?>" class="link <?=($selected ? 'cur_a'  : '')?>"><?=$job['job_title']?></a></td>
                  <?php
               }
            }
            
            $filledNum = 3 - ($n%3);
            if ($filledNum < 3) {
               for ($i=0; $i < $filledNum; $i++) {
                  echo '<td width="33%"></td>';
               }
            }
            ?>
         </tr>
      </table>
   </div>
   <?php endif; ?>
</div>